<?php
// set default counter_id to 1 if not set
if (!defined ("COUNTER_ID")) {
    define ("COUNTER_ID", 1);
}

include dirname(__FILE__) . '/seqs.function.php';

// open the database
$counter_db = new PDO('sqlite:' . dirname(__FILE__) . '/Counter.db');
$counter_db->exec("UPDATE Counters SET Counter = Counter + 1 WHERE Id = " . COUNTER_ID);
$counter_db->exec("INSERT INTO Hits (Counter, Timestamp, RemoteAddr, Referer, SearchKeywords, UserAgent, RequestUri) VALUES (
    " . COUNTER_ID . ", 
    " . time() . ", 
    '" . addslashes(@$_SERVER['REMOTE_ADDR']) . "', 
    '" . addslashes(@$_SERVER['HTTP_REFERER']) . "',
    '" . addslashes(search_engine_query_string()) . "', 
    '" . addslashes(@$_SERVER['HTTP_USER_AGENT']) . "',
    '" . addslashes(@$_SERVER['REQUEST_URI']) . "'
)");

// close the database connection
$counter_db = NULL;

?>
